FROM openanolis/anolisos:8.6

LABEL \
	org.opencontainers.image.title="postgres" \
	org.opencontainers.image.version="10.21-8.6"

RUN set -eux; \
	yum -y update; \
	yum -y install postgresql-server wget; \
	yum clean all

ENV PGDATA /var/lib/pgsql/data

ENV PG_MAJOR 10

ENV PG_VERSION 10.21-2.0.1

ARG TARGETARCH

ENV GOSU_VERSION 1.14

RUN set -eux; \
	wget --timeout=5 --tries=10 -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$TARGETARCH"; \
	wget --timeout=5 --tries=10 -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$TARGETARCH.asc"; \
	export GNUPGHOME="$(mktemp -d)"; \
	for server in $(shuf -e ha.pool.sks-keyservers.net \
	keyserver.ubuntu.com \
	pgp.mit.edu) ; do \
	gpg --keyserver "$server" --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 && break || : ; \
	done && \
	gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
	gpgconf --kill all; \
	rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
	chmod +x /usr/local/bin/gosu; \
	gosu --version; \
	gosu nobody true

RUN mkdir /docker-entrypoint-initdb.d

ENV PGDATA /var/lib/pgsql/data

RUN set -eux; \
	chmod 2777 /var/run/postgresql; \
	chmod 777 "$PGDATA"; \
	sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/share/pgsql/postgresql.conf.sample; \
	grep -F "listen_addresses = '*'" /usr/share/pgsql/postgresql.conf.sample; \
	postgres --version

VOLUME /var/lib/pgsql/data

COPY docker-entrypoint.sh /usr/local/bin/

RUN ln -s usr/local/bin/docker-entrypoint.sh /

ENTRYPOINT ["docker-entrypoint.sh"]

STOPSIGNAL SIGINT

EXPOSE 5432

CMD ["postgres"]
